/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nc.kyiv.yellow.sociallibrary.reporting.data;

import java.util.*;

/**
 * Class, representing piece of reports data in unified form
 * @author NightmaresSeller
 */
public class ReportNode {
    /**
     * The name that identifies node
     */
    private String name;
    /**
     * List of subsequent node of report data
     */
    private List<ReportNode> childNodes;
    /**
     * Attributes, containing data of this node
     */
    private Map<String, Object> attributes;
    
    public ReportNode(String name) {
        this.name = name;
        childNodes = new LinkedList<ReportNode>();
        attributes = new HashMap<String, Object>();
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public Object getAttribute(String name) {
        return attributes.get(name);
    }
    
    public void setAttribute(String name, Object value) {
        attributes.put(name, value);
    }
    
    public List getAttributesNames() {
       return new ArrayList(attributes.keySet());
    }
    
    public void addChild(ReportNode node) {
        childNodes.add(node);
    }
    
    public boolean removeChild(ReportNode node) {
        return childNodes.remove(node);
    }
    
    public boolean containsChild(ReportNode node) {
        return childNodes.contains(node);
    }
    
    public ReportNode getChildAt(int index) {
        return childNodes.get(index);
    }
    
    public List getChildByName(String name) {
        List neededChildren = new ArrayList();
        ReportNode child;
        for (int i = 0; i < getChildCount(); i++) {
            child = getChildAt(i);
            if (child.getName().equals(name)) {
                neededChildren.add(child);
            }
        }
        return neededChildren;
    }
    
    public void addChildAt(ReportNode node, int index) {
        childNodes.add(index, node);
    }
    
    public void removeChildAt(int index) {
        childNodes.remove(index);
    }
    
    public int getChildCount() {
        return childNodes.size();
    }
      
}
